<template>
  <div id="myactivity">
    <scroller class="pointstagli" scrollbar-y lock-x :scroll-bottom-offset="60" @on-scroll-bottom="onScrollBottom1" slot="slist1" ref="scrollerBottom1">
      <div class="mb-msg-t">
        <div class="photograph" ><img :src="data.head_img_url"></div>
        <p class="username">{{data.nick_name}}</p>
        <p class="activityNum">共参与了{{num}}个活动</p>
      </div>
      <div class="activity-list">
        <ul>
          <li v-for="item, id, type in data1" :id="id=item.id":type="type = item.type" @click="routeTo(type,id)">
            <div class="pic">
              <img v-if="item.activityImg === undefined" src="../../assets/images/vote-pic.png">
              <img v-else-if="item.activityImg !== undefined" :src="item.activityImg">
            </div>
            <div class="right">
              <p><span class="title">{{item.activityName}}</span><span class="status">{{item.status}}</span></p>
            </div>
          </li>
        </ul>
        <load-more :value="false" :show-loading="isshowload" :tip="loadtip">Loading</load-more>
      </div>
    </scroller>
  </div>
</template>
<script>
  import { Scroller, LoadMore } from 'vux'
  export default {
    name: 'myactivity',
    components: {
      Scroller,
      LoadMore
    },
    data () {
      return {
        data: {},
        num: 0,
        data1: [],
        pageIndex: 0,
        isupload: false,
        isshowload: false,
        loadtip: '',
        bottomCount1: 0
      }
    },
    created () {
      this.getUserinfo()
      this.getMyActivity()
      .then((data) => {
        this.data1.push.apply(this.data1, data)
        if (data.length > 0) {
          this.bottomCount1 = this.data1.length
        }
      }, () => {})
    },
    methods: {
      // 我的活动
      getMyActivity: function () {
        return this.$axios.post(this.apidomain + '/api/activity/getMyActivityList/' + this.getCookie('appid'), {
          openId: this.getCookie('openid'),
          pageIndex: this.bottomCount1
        })
        .then((response) => {
          if (response.data.errorCode === '0') {
            this.num = response.data.data.activityNum
            return response.data.data.activityList
          } else {
            return []
          }
        })
        .catch(function (error) {
          console.log(error)
          return []
        })
        // this.$axios.post(this.apidomain + '/api/activity/getVipActivity/' + this.getCookie('appid'), {
        //   openId: this.getCookie('openid')
        // })
        // .then((response) => {
        //   if (response.data.errorCode === '0') {
        //     this.num = response.data.data.length
        //     this.data1 = response.data.data
        //   }
        // })
        // .catch((error) => {
        //   console.log(error)
        // })
      },
      onScrollBottom1 () {
        if (this.isupload) {
          this.isshowload = true
          this.loadtip = '加载中...'
        } else {
          this.isupload = true
          setTimeout(() => {
            this.$nextTick(() => {
              this.getMyActivity(this.bottomCount1, 'usable')
              .then((data) => {
                this.data1.push.apply(this.data1, data)
                if (data.length > 0) {
                  this.bottomCount1 = this.data1.length
                }
              }, () => {})
              this.$refs.scrollerBottom1.reset()
              this.isshowload = false
              this.loadtip = ''
              this.isupload = false
            })
          }, 1000)
        }
      },
      routeTo (type, id, state) {
        if (type === 1) {
          this.routeto('activitydetails', { id: id })
        }
        if (type === 2) {
          this.routeto('vote', { id: id, state: state })
        }
      },
      getUserinfo () {
        // let obj = {'sex': 1, 'nickname': '精彩', 'unionid': 'oifXQ1YxlE3TkzNqG5QCM97wG56E', 'privilege': [], 'province': '上海', 'openid': 'o02XP1eVG4VbbEveY4bpvqzB--uk', 'language': 'zh_CN', 'headimgurl': 'http://wx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTIGDNbgTV1hdHgbWZsJGKF97Wo1b4aOkp5PDlbbBnKlUicp5ccukmAQJibKcSb82XZTbF8z90uRxZXA/0', 'country': '中国', 'city': '长宁'}
        // localStorage.userInfo = JSON.stringify(obj)
        // console.log(localStorage.userInfo)
        this.$axios.post(this.apidomain + '/api/cust/getFansInfoByOpenId/' + this.getCookie('appid'), {
          openId: this.getCookie('openid')
        })
        .then((response) => {
          if (response.data.errorCode === '0') {
            this.data = response.data.data
          }
        })
        .catch((error) => {
          console.log(error)
        })
      }
    }
  }
</script>
<style lang="less">
  @import "../../assets/less/myactivity/myactivity.less";
</style>
